home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / comt010d.zip / COMTSRC.ZIP / MAKEHEAD.C < prev    next >
C/C++ Source or Header  |  1991-11-16  |  2KB  |  83 lines

  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <sys/stat.h>
  4.  
  5. #include "safechar.h"
  6.  
  7. int send_esc(char *s,FILE *f)
  8. {
  9.   int newline=0;
  10.   while(*s) switch(*s)
  11.   {
  12.     case '\n': s++; newline=1; break;
  13.     case '\\':
  14.     case '"': putc('\\',f);
  15.     default: putc(*s++,f);
  16.   }
  17.   return newline;
  18. }
  19.  
  20. void putlength(char *pos, int len)
  21. {
  22.   pos[2]=safechar[len%16];
  23.   len/=16;
  24.   pos[1]=safechar[len%16];
  25.   len/=16;
  26.   pos[0]=safechar[len%16];
  27.   len/=16;
  28. }
  29.  
  30. main()
  31. {
  32.   char lin[120];
  33.   time_t rt;
  34.   struct stat sb;
  35.   int l1;
  36.   FILE *in=fopen("ldr.hd","r");
  37.   FILE *out=fopen("header.h","w");
  38.   time(&rt);
  39.   fprintf(out,
  40.         "/* header.h--headers for encoder */\n"
  41.         "/* computer generated from uuldr.hd (obf.bin, uuldr.bin (uuldr.asm)) */\n"
  42.         "/*  and ldr.hd (obf.bin, ldr.bin (ldr.asm)) */\n"
  43.         "/* no user serviceable code */\n"
  44.         "/* data is partly 8086 machine code */\n"
  45.         "/* last generation: %s */\n\n"
  46.         "/* header for method #1: */\n"
  47.         "char nheader[]=\n" , ctime(&rt));
  48.   l1=1;
  49.   while(NULL!=fgets(lin,120,in))
  50.   {
  51.     if(l1)
  52.     {
  53.       fstat(fileno(in),&sb);
  54.       putlength(lin+8,(int)(sb.st_size-8-3));
  55.       l1=0;
  56.     }
  57.     putc('"',out);
  58.     if(send_esc(lin,out)) fputs("\\n",out);
  59.     fputs("\"\n",out);
  60.   }
  61.   fputs(";\n\n"
  62.         "/* header for method #2: */\n"
  63.         "char uheader[]=\n",out);
  64.   fclose(in);
  65.   in=fopen("uuldr.hd","r");
  66.   l1=1;
  67.   while(NULL!=fgets(lin,120,in))
  68.   {
  69.     if(l1)
  70.     {
  71.       fstat(fileno(in),&sb);
  72.       putlength(lin+8,(int)(sb.st_size-8-3));
  73.       l1=0;
  74.     }
  75.     putc('"',out);
  76.     if(send_esc(lin,out)) fputs("\\n",out);
  77.     fputs("\"\n",out);
  78.   }
  79.   fputs(";\n\n/*EOF*/\n",out);
  80.   fcloseall();
  81.   return 0;
  82. }
  83.